//
//  address.cpp
//  TikTok
//
//  Created by 吴尚远 on 2022/5/16.
//

#include "address.h"
//————————————————————————————————————————————————————————————//
address::address()
{
    fan_judge();
    work_judge();
    fri_judge();
    fol_judge();
    black_judge();
}
address::~address()
{
    if(black != NULL)
    {
        delete []black;
        black = NULL;
    }
    if(fol != NULL)
    {
        delete []fol;
        fol = NULL;
    }
    if(fri != NULL)
    {
        delete []fri;
        fri = NULL;
    }
    if(fan != NULL)
    {
        delete []fan;
        fan = NULL;
    }
    if(wor != NULL)
    {
        delete []wor;
        wor = NULL;
    }
}
//————————————————————————————————————————————————————————————//
//判断文件是否为空
void address::work_judge()
{
    //1.文件不存在
    ifstream ifs;
    ifs.open(WORK, ios::in);//读文件
    if (!ifs.is_open())//返回值是bool型
    {
        //cout << "文件不存在" << endl;
        //初始化记录人数
        wor_num = 0;
        //初始化数组指针
        wor = NULL;
        //初始化文件是否为空
        m_FileIsEmpty_work = true;
        ifs.close();
        return;
    }
   //文件存在，但数据为空
    char ch;
    ifs >> ch;
    if(ifs.eof())
    {
        //cout << "文件为空" << endl;
        //初始化记录人数
        wor_num = 0;
        //初始化数组指针
        wor = NULL;
        //初始化文件是否为空
        m_FileIsEmpty_work = true;
        ifs.close();
        return;
    }
    
    //文件存在，并且记录数据
    wor_num = work_get_EmpNum();
    
    //开辟空间
    wor = new work[wor_num];
    //将文件中的数据存到数组中
    work_init();
    //更新标志
    m_FileIsEmpty_work = false;
}
//读取文件中的作品数量
int address::work_get_EmpNum()
{
    ifstream ifs;
    ifs.open(WORK, ios::in);//打开文件 -- 读
    string name;
    int size;
    int views;
    int likes;
    int comments;
    int year;
    int month;
    int day;
    bool privacy;
    int num = 0;//记录数量
    while (ifs >> name && ifs >> size && ifs >> views && ifs >> likes && ifs >> comments && ifs >> year && ifs >> month && ifs >> day && ifs >> privacy)
    {
        num++;
    }
    ifs.close();
    return num;
}
//初始化
void address::work_init()
{
    ifstream ifs;
    ifs.open(WORK, ios::in);

    string name;
    int size;
    int views;
    int likes;
    int comments;
    int year;
    int month;
    int day;
    bool privacy;
    int index = 0;
    while (ifs >> name && ifs >> size && ifs >> views && ifs >> likes && ifs >> comments && ifs >> year && ifs >> month && ifs >> day && ifs >> privacy)
    {
        wor[index].name = name;
        wor[index].size = size;
        wor[index].views = views;
        wor[index].likes = likes;
        wor[index].comments = comments;
        wor[index].time.year = year;
        wor[index].time.month = month;
        wor[index].time.day = day;
        wor[index].privacy = privacy;
        index++;
    }
   
    ifs.close();
}
//保存文件
void address::work_save()
{
    ofstream ofs;
    ofs.open(WORK, ios::out);//用输出的方式打开文件 -- 写文件
    for(int i = 0; i < wor_num; i++)
    {
        ofs << wor[i].name << " "
        << wor[i].size << " "
        << wor[i].views << " "
        << wor[i].likes << " "
        << wor[i].comments << " "
        << wor[i].time.year << " "
        << wor[i].time.month << " "
        << wor[i].time.day << " "
        << wor[i].privacy << endl;
    }
    
    //关闭文件
    ofs.close();
}
//清空文件
void address::work_Clean()
{
    while(1)
    {
        cout << "确认清空？" << endl;
        cout << "1.确认" << endl;
        cout << "2.返回" << endl;
        int select = 0;
        cin >> select;
        if(select == 1)
        {
            //打开模式 ios::trunc 如果存在，则删除文件并重新创建
            ofstream ofs(WORK, ios::trunc);
            ofs.close();
            if (wor != NULL)
            {
                delete []wor;
                wor_num = 0;
                wor = NULL;
                m_FileIsEmpty_work = true;
            }
            cout << "清除成功！" << endl;
            break;
        }
        else if(select == 2)
        {
            break;
        }
        else
        {
            cout << "您的输入有误，请重新输入！" << endl;
        }
    }
}
//添加喜欢
void address::Add_like()
{
    //功能描述：发布新作品，并且保存到文件中
   while (1)
   {
        cout << "请输入添加作品数量：" << endl;
        int add_num = 0;//保存发布作品的输入数量
        cin >> add_num;
        bool flag = false;
        if(add_num > 0)
        {
            //计算新空间的大小
            int newSize = wor_num + add_num;
            //开辟新空间
            work * newSpace = new work[newSize];
            //将原空间下内容拷贝到新空间下
            if(wor != NULL)
            {
                for(int i = 0; i < wor_num; i++)
                {
                    newSpace[i] = wor[i];
                }
            }
            //输入新数据
            for(int j = 0; j < add_num; j++)
            {
                //创立一个临时的对象用于储存新增加的作品
                work short_time;
                cout << "请输入第" << j+1 << "个作品的名字：" << endl;
                cin >> short_time.name;
                    
                cout << "请输入第" << j+1 << "个作品的大小：" << endl;
                cin >> short_time.size;
                cout << "请输入第" << j+1 << "个作品的被浏览量：" << endl;
                cin >> short_time.views;
                cout << "请输入第" << j+1 << "个作品的被点赞量：" << endl;
                cin >> short_time.likes;
                cout << "请输入第" << j+1 << "个作品的被评论量：" << endl;
                cin >> short_time.comments;
                //检验作品发布的时间是否正常
                while(1)
                {
                    cout << "请输入第" << j+1 << "个作品发布的时间：" << endl;
                    cout << "年：";
                    int short_year;
                    cin >> short_year;
                    cout << "月：";
                    int short_month;
                    cin >> short_month;
                    cout << "日：";
                    int short_day;
                    cin >> short_day;
                    if(date().Check_time(short_year, short_month, short_day))
                    {
                        short_time.time.year = short_year;
                        short_time.time.month = short_month;
                        short_time.time.day = short_day;
                        break;
                    }
                    else
                    {
                        cout << "这是一个错误的日期，请重新输入！" << endl;
                    }
                }
               
                //发布作品完成后，保存到数组中
                newSpace[wor_num+j] = short_time;
            }
            //释放在堆区创建的内存
            delete[] wor;
            //更改新空间的指向
            wor = newSpace;
            //更新新的作品数
            wor_num = newSize;
            //更改标志
            m_FileIsEmpty_work = false;
            //保存到文件里
            work_save();
            
             //提示添加成功
            cout << "成功发布" << add_num << "个作品" << endl;
        }
        else
        {
            cout << "请重新输入" << endl;
        }
        if(flag == false)
        {
            break;
        }
    }
}
//作品列表展示
void address::work_list()
{
    if(m_FileIsEmpty_work == false)
    {
        for(int i = 0; i < wor_num; i++)
            {
                cout << "名字：" << wor[i].name << "\t";
                cout << "大小：" << wor[i].size << "\t";
                cout << "被点赞量：" << wor[i].likes << "\t";
                cout << "被浏览量：" << wor[i].views << "\t";
                cout << "被评论量：" << wor[i].comments << "\t";
                cout << "日期：" <<  wor[i].time.year << "/" << wor[i].time.month << "/" << wor[i].time.day << endl;
            }
    }
    else
    {
        cout << "文件是一个空文件，没有数据！" << endl;
    }
            
}
//按照作品名排序
void address::rank_name(int num)
{
    if(m_FileIsEmpty_work == true)
    {
        cout << "文件为空文件，没有数据！" << endl;
    }
    else
    {
        for(int i = 0; i < num - 1; i++)
        {
            for(int j = 0; j < num-1-i; j++)
            {
                if(wor[j].name > wor[j+1].name)
                {
                    work temp = wor[j+1];
                    wor[j+1] = wor[j];
                    wor[j] = temp;
                }
            }
        }
        for(int k = 0; k < num; k++)
        {
            cout << "名字：" << wor[k].name << "\t";
            cout << "大小：" << wor[k].size << "\t";
            cout << "被点赞量：" << wor[k].likes << "\t";
            cout << "被浏览量：" << wor[k].views << "\t";
            cout << "被评论量：" << wor[k].comments << "\t";
            cout << "日期：" << wor[k].time.year << "/" << wor[k].time.month << "/" << wor[k].time.day << endl;
        }
    }
    
}
//按照作品时间排序
void address::rank_time(int num)
{
    if(m_FileIsEmpty_work == true)
    {
        cout << "文件为空文件，没有数据！" << endl;
    }
    else
    {
        for(int i = 0; i < num - 1; i++)
        {
            for(int j = 0; j < num-1-i; j++)
            {
                //时间比对较为复杂，所以可以更改思路，将年月日统一成一个单位进行比对
                //这里假设一年等于十二个月，一个月等于三十天，或者其他的数值均是一般
                //作用均为统一比较标准
                int first;
                int second;
                first = 12 * 30 * wor[j].time.year + 30 * wor[j].time.month + wor[j].time.day;
                second = 12 * 30 * wor[j+1].time.year + 30 * wor[j+1].time.month + wor[j+1].time.day;
                if(first > second)
                {
                    work temp = wor[j+1];
                    wor[j+1] = wor[j];
                    wor[j] = temp;
                }
            }
        }
        for(int k = 0; k < num; k++)
        {
            cout << "名字：" << wor[k].name << "\t";
            cout << "大小：" << wor[k].size << "\t";
            cout << "被点赞量：" << wor[k].likes << "\t";
            cout << "被浏览量：" << wor[k].views << "\t";
            cout << "被评论量：" << wor[k].comments << "\t";
            cout << "日期：" << wor[k].time.year << "/" << wor[k].time.month << "/" << wor[k].time.day << endl;
        }
    }
    
}
//————————————————————————————————————————————————————————————//
//通讯录管理菜单
void address::ad_menu()
{
    while(1)
    {
        cout << "欢迎来到通讯录管理系统，请输入您想要进行的操作：" << endl;
        cout << "0.返回上一级菜单" << endl;
        cout << "1.我的好友" << endl;
        cout << "2.我的关注" << endl;
        cout << "3.我的粉丝" << endl;
        cout << "4.我的喜欢" << endl;
        cout << "5.我的黑名单" << endl;
        int choose;
        cin >> choose;
        switch (choose)
        {
            case 0:
                return;
            case 1:
                fri_menu();
                break;
            case 2:
                fol_menu();
                break;
            case 3:
                fan_menu();
                break;
            case 4:
                like_menu();
                break;
            case 5:
                black_menu();
                break;
            default:
                cout << "您的输入有误，请重新输入！" << endl;
                break;
        }
    }
        

}
//好友菜单
void address::fri_menu()
{
    while(1)
    {
        cout << "请选择您想要进行的操作：" << endl;
        cout << "0.返回上一级菜单" << endl;
        cout << "1.展示好友列表" << endl;
        cout << "2.搜索好友" << endl;
        cout << "3.设置关注" << endl;
        cout << "4.拉黑好友" << endl;
        cout << "5.添加好友" << endl;
        cout << "6.清空文件" << endl;
        
        int choose;
        cin >> choose;
        switch(choose)
        {
            case 0:
                return;
            case 1:
                fri_list();
                break;
            case 2:
                fri_search();
                break;
            case 3:
                fri_setFol();
                break;
            case 4:
                fri_setBlack();
                break;
            case 5:
                Add_fri();
                break;
            case 6:
                fri_Clean();
                break;
            default:
                cout << "您的输入有误，请重新输入！" << endl;
                break;
        }
    }
    
}
//关注菜单
void address::fol_menu()
{
    while(1)
    {
        cout << "请选择您想要进行的操作：" << endl;
        cout << "0.返回上一级菜单" << endl;
        cout << "1.展示关注列表" << endl;
        cout << "2.搜索我的关注" << endl;
        cout << "3.取消关注" << endl;
        cout << "4.拉黑" << endl;
        cout << "5.搜索用户，并关注" << endl;
        cout << "6.清空文件" << endl;
        
        int choose;
        cin >> choose;
        switch(choose)
        {
            case 0:
                return;
            case 1:
                fol_list();
                break;
            case 2:
                fol_list();
                break;
            case 3:
                fol_outFol();
                break;
            case 4:
                fol_setBlack();
                break;
            case 5:
                Add_fol();
                break;
            case 6:
                fol_Clean();
                break;
                
            default:
                cout << "您的输入有误，请重新输入！" << endl;
                break;
        }
    }
}
//粉丝菜单
void address::fan_menu()
{
    while(1)
    {
        cout << "请选择您想要进行的操作：" << endl;
        cout << "0.返回上一级菜单" << endl;
        cout << "1.展示粉丝列表" << endl;
        cout << "2.搜索粉丝" << endl;
        cout << "3.设置关注" << endl;
        cout << "4.拉黑粉丝" << endl;
        cout << "5.清空文件" << endl;
        
        int choose;
        cin >> choose;
        switch(choose)
        {
            case 0:
                return;
            case 1:
                fan_list();
                break;
            case 2:
                fan_search();
                break;
            case 3:
                fan_setFol();
                break;
            case 4:
                fan_setBlack();
                break;
            case 5:
                fan_Clean();
                break;
            default:
                cout << "您的输入有误，请重新输入！" << endl;
                break;
        }
    }
}
//喜欢菜单
void address::like_menu()
{
    while(1)
    {
        cout << "请选择您想要进行的操作：" << endl;
        cout << "0.返回上一级菜单" << endl;
        cout << "1.展示喜欢列表" << endl;
        cout << "2.增加喜欢作品" << endl;
        cout << "3.按照时间顺序排序作品" << endl;
        cout << "4.按照名称顺序排序作品" << endl;
        cout << "5.清空喜欢作品" << endl;
        int choose;
        cin >> choose;
        switch(choose)
        {
            case 0:
                return;
            case 1:
                for(int i = 0; i < wor_num; i++)
                {
                    cout << wor[i].name << endl;
                }
                break;
            case 2:
                Add_like();
                //T_search(fan_num, fan);
                break;
            case 3:
                rank_time(wor_num);
                break;
            case 4:
                rank_name(wor_num);
                break;
            case 5:
                work_Clean();
                break;
            default:
                cout << "您的输入有误，请重新输入！" << endl;
                break;
        }
    }
}
//黑名单菜单
void address::black_menu()
{
    while(1)
    {
        cout << "请输入您想要进行的操作：" << endl;
        cout << "0.返回上一级菜单" << endl;
        cout << "1.展示黑名单列表" << endl;
        cout << "2.搜索" << endl;
        cout << "3.拉出黑名单" << endl;
        cout << "4.搜索用户，并将其拉入黑名单" << endl;
        cout << "5.清空黑名单" << endl;
        
        int choose;
        cin >> choose;
        switch(choose)
        {
            case 0:
                return;
            case 1:
                black_list();
                break;
            case 2:
                black_search();
                break;
            case 3:
                black_outBlack();
                break;
            case 4:
                Add_black();
                break;
            case 5:
                black_Clean();
                break;
            default:
                cout << "您的输入有误，请重新输入！" << endl;
                break;
        }
    }
    
}


//————————————————————————————————————————————————————————————//
//————————————————————————————————————————————————————————————//
//————————————————————————————————————————————————————————————//
//————————————————————————————————————————————————————————————//

//判断文件是否为空
void address::fri_judge()
{
        //1.文件不存在
        ifstream ifs;
        ifs.open(FILE_FRI, ios::in);//读文件
        if (!ifs.is_open())//返回值是bool型
        {
            //cout << "文件不存在" << endl;
            //初始化记录人数
            fri_num = 0;
            //初始化数组指针
            fri = NULL;
            //初始化文件是否为空
            m_FileIsEmpty_fri = true;
            ifs.close();
            return;
        }
       //文件存在，但数据为空
        char ch;
        ifs >> ch;
        if(ifs.eof())
        {
            //cout << "文件为空" << endl;
            //初始化记录人数
            fri_num = 0;
            //初始化数组指针
            fri = NULL;
            //初始化文件是否为空
            m_FileIsEmpty_fri = true;
            ifs.close();
            return;
        }
        
        //文件存在，并且记录数据
        fri_num = fri_get_EmpNum();
        
        //开辟空间
        fri = new pro[fri_num];
        //将文件中的数据存到数组中
        fri_init();
        //更新职工不为空标志
        m_FileIsEmpty_fri = false;
}
//统计文件中人数
int address::fri_get_EmpNum()
{
        ifstream ifs;
        ifs.open(FILE_FRI, ios::in);//打开文件 -- 读
        string username;//昵称
        string name;//真实姓名
        string ID;//抖音号
        string bio;//个人简介
        string mail_box;//邮箱
        string school;//学校
        string area;//地区
        int year;//生日
        int month;
        int day;
        char sex;//性别
        int likes;//总获赞数
        int num = 0;//记录数量
        while (ifs >> username && ifs >> name && ifs >> ID && ifs >> bio && ifs >> mail_box && ifs >> school && ifs >> year && ifs >> month && ifs >> day && ifs >> area && ifs >> sex && ifs >> likes)
        {
            num++;
        }
        ifs.close();
        return num;
}
//初始化
void address::fri_init()
{
        ifstream ifs;
        ifs.open(FILE_FRI, ios::in);

        string username;//昵称
        string name;//真实姓名
        string ID;//抖音号
        string bio;//个人简介
        string mail_box;//邮箱
        string school;//学校
        string area;//地区
        int year;//生日
        int month;
        int day;
        char sex;//性别
        int likes;//总获赞数
        int index = 0;
        while (ifs >> username && ifs >> name && ifs >> ID && ifs >> bio && ifs >> mail_box && ifs >> school && ifs >> year && ifs >> month && ifs >> day && ifs >> area && ifs >> sex && ifs >> likes)
        {
            fri[index].username = username;
            fri[index].name = name;
            fri[index].ID = ID;
            fri[index].bio = bio;
            fri[index].mail_box = mail_box;
            fri[index].school = school;
            fri[index].birthday.year = year;
            fri[index].birthday.month = month;
            fri[index].birthday.day = day;
            fri[index].area = area;
            fri[index].sex = sex;
            fri[index].likes = likes;
            index++;
        }
       
        ifs.close();
}
//保存文件
void address::fri_save()
{
        ofstream ofs;
        ofs.open(FILE_FRI, ios::out);//用输出的方式打开文件 -- 写文件
        for(int i = 0; i < fri_num; i++)
        {
            ofs << fri[i].username << " "
            << fri[i].name << " "
            << fri[i].ID << " "
            << fri[i].bio << " "
            << fri[i].mail_box << " "
            << fri[i].school << " "
            << fri[i].birthday.year << " "
            << fri[i].birthday.month << " "
            << fri[i].birthday.day << " "
            << fri[i].area << " "
            << fri[i].sex << " "
            << fri[i].likes << endl;
        }
        //关闭文件
        ofs.close();
}
//清空文件
void address::fri_Clean()
{
        if(m_FileIsEmpty_fri == true)
        {
            cout << "这是个空文件，无法删除！" << endl;
        }
        else
        {
            while(1)
            {
                cout << "确认清空？" << endl;
                cout << "1.确认" << endl;
                cout << "2.返回" << endl;
                int select = 0;
                cin >> select;
                if(select == 1)
                {
                    //打开模式 ios::trunc 如果存在，则删除文件并重新创建
                    ofstream ofs(FILE_FRI, ios::trunc);
                    ofs.close();
                    if (fri != NULL)
                    {
                        delete []fri;
                        fri_num = 0;
                        fri = NULL;
                        m_FileIsEmpty_fri = true;
                    }
                    cout << "清除成功！" << endl;
                    break;
                }
                else if(select == 2)
                {
                    break;
                }
                else
                {
                    cout << "您的输入有误，请重新输入！" << endl;
                }
            }
        }
       
}
//添加好友
void address::Add_fri()
{
    
       while (1)
       {
            cout << "请输入添加的用户数量：" << endl;
            int add_num = 0;
            cin >> add_num;
            bool flag = false;
            if(add_num > 0)
            {
                //计算新空间的大小
                int newSize = fri_num + add_num;
                //开辟新空间
                pro * newSpace = new pro[newSize];
                //将原空间下内容拷贝到新空间下
                if(fri != NULL)
                {
                    for(int i = 0; i < fri_num; i++)
                    {
                        newSpace[i] = fri[i];
                    }
                }
                //输入新数据
                for(int j = 0; j < add_num; j++)
                {
                    //创立一个临时的数组用于储存新增加的数据
                    pro short_time;
                    pro & shor = short_time;
                    cout << "请输入博主的昵称:";
                    cin >> short_time.username;
                    cout << "请输入博主的真实姓名：";
                    cin >> short_time.name;
                    cout << "请输入博主的抖音号:";
                    cin >> short_time.ID;
                    cout << "请输入博主的个人简介:" ;
                    cin >> short_time.bio;
                    cout << "请输入博主的邮箱:" ;
                    cin >> short_time.mail_box;
                    cout << "请输入博主的学校:" ;
                    cin >> short_time.school;
                    //添加地区
                    pro_management().set_area(shor);
                    //录入生日
                    pro_management().set_bir(shor);
                    //录入性别
                    pro_management().set_sex(shor);
                    cout << "请输入博主的总获赞数:" ;
                    cin >> short_time.likes;
                    newSpace[fri_num + j] = short_time;
                    
                }
                //将原来的数据清空
                delete []fri;
                fri = newSpace;
                fri_num = newSize;
                cout << "添加成功！" << endl;
                //保存数据到文件中
                fri_save();
                //更改mFileEmpty
                m_FileIsEmpty_fri = false;
            
             //提示添加成功
            cout << "成功将" << add_num << "个用户" << "加为好友！" << endl;
            }
            else
            {
                cout << "请重新输入" << endl;
            }
            if(flag == false)
            {
                break;
            }
        }
}

//展示列表
void address::fri_list()
{
        
        if(m_FileIsEmpty_fri == false)
        {
            for(int i = 0; i < fri_num; i++)
                {
                    cout << "昵称：" << fri[i].username << endl;
                    cout << "真实姓名：" << fri[i].name << endl;
                    cout << "抖音号：" << fri[i].ID << endl;
                    cout << "邮箱：" << fri[i].mail_box << endl;
                    cout << "学校：" << fri[i].school << endl;
                    cout << "性别：" << fri[i].sex << endl;
                    cout << "生日：" << fri[i].birthday.year << "/"
                         << fri[i].birthday.month << "/"
                         << fri[i].birthday.day << endl;
                    cout << "地区：" << fri[i].area << endl;
                    cout << "总点赞数：" << fri[i].likes << endl;
                    
                    cout << "个人简介：" << fri[i].bio << endl;
                    cout << "\n\n";
                }
        }
        else
        {
            cout << "文件是一个空文件，没有数据！" << endl;
        }
        
}
//搜索功能
void address::fri_search()
{
    if(m_FileIsEmpty_fri == false)
    {
        while(1)
        {
            cout << "请输入您想要使用哪种搜索方式" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.昵称搜索" << endl;
            cout << "2.账号搜索" << endl;
            int choose;
            cin >> choose;
            if(choose == 0)
            {
                return;
            }
            if(choose == 1)
            {
                cout << "请输入您想要搜索的昵称：" << endl;
                string name;
                cin >> name;
                bool flag = false;
                for(int j = 0; j < fri_num; j++)
                {
                    if(name == fri[j].username)
                    {
                        //cout << m_pro[j].username << endl;
                        cout << "昵称：" << fri[j].username << endl;
                        cout << "真实姓名：" << fri[j].name << endl;
                        cout << "抖音号：" << fri[j].ID << endl;
                        cout << "邮箱：" << fri[j].mail_box << endl;
                        cout << "学校：" << fri[j].school << endl;
                        cout << "性别：" << fri[j].sex << endl;
                        cout << "生日：" << fri[j].birthday.year << "/"
                             << fri[j].birthday.month << "/"
                             << fri[j].birthday.day << endl;
                        cout << "地区：" << fri[j].area << endl;
                        cout << "总点赞数：" << fri[j].likes << endl;
                        
                        cout << "个人简介：" << fri[j].bio << endl;
                        cout << "\n\n";
                        flag = true;
                    }
                    
                }
                if(flag == false)
                {
                    cout << "查无此人！" << endl;
                }
                break;
            }
            else if(choose == 2)
            {
                cout << "请输入您想要搜索的账号：" << endl;
                string ID;
                cin >> ID;
                for(int k = 0; k < fri_num; k++)
                {
                    if(ID == fri[k].ID)
                    {
                        //cout << m_pro[k].ID << endl;
                        cout << "昵称：" << fri[k].username << endl;
                        cout << "真实姓名：" << fri[k].name << endl;
                        cout << "抖音号：" << fri[k].ID << endl;
                        cout << "邮箱：" << fri[k].mail_box << endl;
                        cout << "学校：" << fri[k].school << endl;
                        cout << "性别：" << fri[k].sex << endl;
                        cout << "生日：" << fri[k].birthday.year << "/"
                             << fri[k].birthday.month << "/"
                             << fri[k].birthday.day << endl;
                        cout << "地区：" << fri[k].area << endl;
                        cout << "总点赞数：" << fri[k].likes << endl;
                        
                        cout << "个人简介：" << fri[k].bio << endl;
                        cout << "\n\n";
                    }
                }
                break;
            }
            else
            {
                cout << "您的输入有误，请重新输入！" << endl;
            }
        }
    }
    else
    {
        cout << "文件是个空文件，没有数据！" << endl;
    }
}
//拉黑
void address::fri_setBlack()
{
    cout << "请通过以下两种方式确定用户" << endl;
    cout << "0.返回上一级菜单" << endl;
    cout << "1.按照列表查找" << endl;
    cout << "2.搜索" << endl;
    int choice;
    cin >> choice;
    
    while(1)
    {
        if(choice == 0)
        {
            return;
        }
        if(choice == 1)
        {
            fri_list();
        }
        else if(choice != 1 && choice != 2)
        {
            cout << "您的输入有误，请重新输入！" << endl;
            cout << "请通过以下两种方式确定用户" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.按照列表查找" << endl;
            cout << "2.搜索" << endl;
            cin >> choice;
            //用continue的特性，重新输入
            continue;
        }
        cout << "请输入该用户的用户名：" << endl;
        string name;
        cin >> name;
        //加入判断字符，判断是否存在该用户
        bool flag = false;
        for(int i = 0; i < fri_num; i++)
        {
            if(name == fri[i].username)
            {
                //更新数组长度
                int new_size;
                new_size = black_num + 1;
                //重新在堆区申请内存
                pro * new_black = new pro[new_size];
                //若有人在黑名单里
                if (black != NULL)
                {
                    //将原来的数据拷贝到新的数组里
                    for(int j = 0; j < black_num; j++)
                    {
                         new_black[j] = black[j];
                    }
                    //把想要拉黑的用户拉黑
                    new_black[new_size - 1] = fri[i];
                }
                //若无人在黑名单里
                else
                {
                    //把这个人设置为黑名单的第一个人
                    new_black[black_num] = fri[i];
                }
                //清空堆区数据
                delete []black;
                //更新数组
                black = new_black;
                black_num = new_size;
                //更新标志
                flag = true;
                //输出提示
                cout << "成功拉黑！" << endl;
                //保存到文件中
                black_save();
                //fri_save();
                m_FileIsEmpty_black = false;
            }
            
        }
        if(flag == false)
        {
            cout << "查无此人，请重新输入！" << endl;
            cout << "请通过以下两种方式确定用户" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.按照列表查找" << endl;
            cout << "2.搜索" << endl;
            cin >> choice;
            //用continue的特性，重新输入
            continue;
        }
        break;
    }
}
//关注
void address::fri_setFol()
{
    cout << "请通过以下两种方式确定用户" << endl;
    cout << "0.返回上一级菜单" << endl;
    cout << "1.按照列表查找" << endl;
    cout << "2.搜索" << endl;
    int choice;
    cin >> choice;
    
    while(1)
    {
        if(choice == 0)
        {
            return;
        }
        if(choice == 1)
        {
            fri_list();
        }
        else if(choice != 1 && choice != 2)
        {
            cout << "您的输入有误，请重新输入！" << endl;
            cout << "请通过以下两种方式确定用户" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.按照列表查找" << endl;
            cout << "2.搜索" << endl;
            cin >> choice;
            //用continue的特性，重新输入
            continue;
        }
        cout << "请输入该用户的用户名：" << endl;
        string name;
        cin >> name;
        //加入判断字符，判断是否存在该用户
        bool flag = false;
        for(int i = 0; i < fri_num; i++)
        {
            if(name == fri[i].username)
            {
                //更新数组长度
                int new_size;
                new_size = fol_num + 1;
                //重新在堆区申请内存
                pro * new_black = new pro[new_size];
                //若有人在关注里
                if (fol != NULL)
                {
                    //将原来的数据拷贝到新的数组里
                    for(int j = 0; j < fol_num; j++)
                    {
                         new_black[j] = fol[j];
                    }
                    //把想要关注的用户关注
                    new_black[new_size - 1] = fri[i];
                }
                //若无人在关注里
                else
                {
                    //把这个人设置为关注的第一个人
                    new_black[fol_num] = fri[i];
                }
                //清空堆区数据
                delete []fol;
                //更新数组
                fol = new_black;
                fol_num = new_size;
                //更新标志
                flag = true;
                //输出提示
                cout << "成功关注！！" << endl;
                //保存到文件中
                fol_save();
                //fri_save();
                m_FileIsEmpty_fol = false;
            }
            
        }
        if(flag == false)
        {
            cout << "查无此人，请重新输入！" << endl;
            cout << "请通过以下两种方式确定用户" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.按照列表查找" << endl;
            cout << "2.搜索" << endl;
            cin >> choice;
            //用continue的特性，重新输入
            continue;
        }
        break;
    }
}
//————————————————————————————————————————————————————————————//

//判断文件是否为空
void address::fol_judge()
{
        //1.文件不存在
        ifstream ifs;
        ifs.open(FILE_FOL, ios::in);//读文件
        if (!ifs.is_open())//返回值是bool型
        {
            //cout << "文件不存在" << endl;
            //初始化记录人数
            fol_num = 0;
            //初始化数组指针
            fol = NULL;
            //初始化文件是否为空
            m_FileIsEmpty_fol = true;
            ifs.close();
            return;
        }
       //文件存在，但数据为空
        char ch;
        ifs >> ch;
        if(ifs.eof())
        {
            //cout << "文件为空" << endl;
            //初始化记录人数
            fol_num = 0;
            //初始化数组指针
            fol = NULL;
            //初始化文件是否为空
            m_FileIsEmpty_fol = true;
            ifs.close();
            return;
        }
        
        //文件存在，并且记录数据
        fol_num = fol_get_EmpNum();
        
        //开辟空间
    fol = new pro[fol_num];
        //将文件中的数据存到数组中
    fol_init();
        //更新职工不为空标志
        m_FileIsEmpty_fol = false;
}
//统计文件中人数
int address::fol_get_EmpNum()
{
        ifstream ifs;
        ifs.open(FILE_FOL, ios::in);//打开文件 -- 读
        string username;//昵称
        string name;//真实姓名
        string ID;//抖音号
        string bio;//个人简介
        string mail_box;//邮箱
        string school;//学校
        string area;//地区
        int year;//生日
        int month;
        int day;
        char sex;//性别
        int likes;//总获赞数
        int num = 0;//记录数量
        while (ifs >> username && ifs >> name && ifs >> ID && ifs >> bio && ifs >> mail_box && ifs >> school && ifs >> year && ifs >> month && ifs >> day && ifs >> area && ifs >> sex && ifs >> likes)
        {
            num++;
        }
        ifs.close();
        return num;
}
//初始化
void address::fol_init()
{
        ifstream ifs;
        ifs.open(FILE_FOL, ios::in);

        string username;//昵称
        string name;//真实姓名
        string ID;//抖音号
        string bio;//个人简介
        string mail_box;//邮箱
        string school;//学校
        string area;//地区
        int year;//生日
        int month;
        int day;
        char sex;//性别
        int likes;//总获赞数
        int index = 0;
        while (ifs >> username && ifs >> name && ifs >> ID && ifs >> bio && ifs >> mail_box && ifs >> school && ifs >> year && ifs >> month && ifs >> day && ifs >> area && ifs >> sex && ifs >> likes)
        {
            fol[index].username = username;
            fol[index].name = name;
            fol[index].ID = ID;
            fol[index].bio = bio;
            fol[index].mail_box = mail_box;
            fol[index].school = school;
            fol[index].birthday.year = year;
            fol[index].birthday.month = month;
            fol[index].birthday.day = day;
            fol[index].area = area;
            fol[index].sex = sex;
            fol[index].likes = likes;
            index++;
        }
       
        ifs.close();
}
//保存文件
void address::fol_save()
{
        ofstream ofs;
        ofs.open(FILE_FOL, ios::out);//用输出的方式打开文件 -- 写文件
        for(int i = 0; i < fol_num; i++)
        {
            ofs << fol[i].username << " "
            << fol[i].name << " "
            << fol[i].ID << " "
            << fol[i].bio << " "
            << fol[i].mail_box << " "
            << fol[i].school << " "
            << fol[i].birthday.year << " "
            << fol[i].birthday.month << " "
            << fol[i].birthday.day << " "
            << fol[i].area << " "
            << fol[i].sex << " "
            << fol[i].likes << endl;
        }
        //关闭文件
        ofs.close();
}

//清空文件
void address::fol_Clean()
{
        if(m_FileIsEmpty_fol == true)
        {
            cout << "这是个空文件，无法删除！" << endl;
        }
        else
        {
            while(1)
            {
                cout << "确认清空？" << endl;
                cout << "1.确认" << endl;
                cout << "2.返回" << endl;
                int select = 0;
                cin >> select;
                if(select == 1)
                {
                    //打开模式 ios::trunc 如果存在，则删除文件并重新创建
                    ofstream ofs(FILE_FOL, ios::trunc);
                    ofs.close();
                    if (fol != NULL)
                    {
                        delete []fol;
                        fol_num = 0;
                        fol = NULL;
                        m_FileIsEmpty_fol = true;
                    }
                    cout << "清除成功！" << endl;
                    break;
                }
                else if(select == 2)
                {
                    break;
                }
                else
                {
                    cout << "您的输入有误，请重新输入！" << endl;
                }
            }
        }
       
}
//添加好友
void address::Add_fol()
{
    
       while (1)
       {
            cout << "请输入添加的用户数量：" << endl;
            int add_num = 0;
            cin >> add_num;
            bool flag = false;
            if(add_num > 0)
            {
                //计算新空间的大小
                int newSize = fol_num + add_num;
                //开辟新空间
                pro * newSpace = new pro[newSize];
                //将原空间下内容拷贝到新空间下
                if(fol != NULL)
                {
                    for(int i = 0; i < fol_num; i++)
                    {
                        newSpace[i] = fol[i];
                    }
                }
                //输入新数据
                for(int j = 0; j < add_num; j++)
                {
                    //创立一个临时的数组用于储存新增加的数据
                    pro short_time;
                    pro & shor = short_time;
                    cout << "请输入博主的昵称:";
                    cin >> short_time.username;
                    cout << "请输入博主的真实姓名：";
                    cin >> short_time.name;
                    cout << "请输入博主的抖音号:";
                    cin >> short_time.ID;
                    cout << "请输入博主的个人简介:" ;
                    cin >> short_time.bio;
                    cout << "请输入博主的邮箱:" ;
                    cin >> short_time.mail_box;
                    cout << "请输入博主的学校:" ;
                    cin >> short_time.school;
                    //添加地区
                    pro_management().set_area(shor);
                    //录入生日
                    pro_management().set_bir(shor);
                    //录入性别
                    pro_management().set_sex(shor);
                    cout << "请输入博主的总获赞数:" ;
                    cin >> short_time.likes;
                    newSpace[fol_num + j] = short_time;
                    
                }
                //将原来的数据清空
                delete []fol;
                fol = newSpace;
                fol_num = newSize;
                cout << "添加成功！" << endl;
                //保存数据到文件中
                fol_save();
                //更改mFileEmpty
                m_FileIsEmpty_fol = false;
            
             //提示添加成功
            cout << "成功将" << add_num << "个用户" << "加为好友！" << endl;
            }
            else
            {
                cout << "请重新输入" << endl;
            }
            if(flag == false)
            {
                break;
            }
        }
}

//展示列表
void address::fol_list()
{
        if(m_FileIsEmpty_fol == false)
        {
            for(int i = 0; i < fri_num; i++)
                {
                    cout << "昵称：" << fol[i].username << endl;
                    cout << "真实姓名：" << fol[i].name << endl;
                    cout << "抖音号：" << fol[i].ID << endl;
                    cout << "邮箱：" << fol[i].mail_box << endl;
                    cout << "学校：" << fol[i].school << endl;
                    cout << "性别：" << fol[i].sex << endl;
                    cout << "生日：" << fol[i].birthday.year << "/"
                         << fol[i].birthday.month << "/"
                         << fol[i].birthday.day << endl;
                    cout << "地区：" << fol[i].area << endl;
                    cout << "总点赞数：" << fol[i].likes << endl;
                    
                    cout << "个人简介：" << fol[i].bio << endl;
                    cout << "\n\n";
                }
        }
        else
        {
            cout << "文件是一个空文件，没有数据！" << endl;
        }
        
}
//搜索功能
void address::fol_search()
{
    if(m_FileIsEmpty_fol == false)
    {
        while(1)
        {
            cout << "请输入您想要使用哪种搜索方式" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.昵称搜索" << endl;
            cout << "2.账号搜索" << endl;
            int choose;
            cin >> choose;
            if(choose == 0)
            {
                return;
            }
            if(choose == 1)
            {
                cout << "请输入您想要搜索的昵称：" << endl;
                string name;
                cin >> name;
                bool flag = false;
                for(int j = 0; j < fol_num; j++)
                {
                    if(name == fol[j].username)
                    {
                        //cout << m_pro[j].username << endl;
                        cout << "昵称：" << fol[j].username << endl;
                        cout << "真实姓名：" << fol[j].name << endl;
                        cout << "抖音号：" << fol[j].ID << endl;
                        cout << "邮箱：" << fol[j].mail_box << endl;
                        cout << "学校：" << fol[j].school << endl;
                        cout << "性别：" << fol[j].sex << endl;
                        cout << "生日：" << fol[j].birthday.year << "/"
                             << fol[j].birthday.month << "/"
                             << fol[j].birthday.day << endl;
                        cout << "地区：" << fol[j].area << endl;
                        cout << "总点赞数：" << fol[j].likes << endl;
                        
                        cout << "个人简介：" << fol[j].bio << endl;
                        cout << "\n\n";
                        flag = true;
                    }
                    
                }
                if(flag == false)
                {
                    cout << "查无此人！" << endl;
                }
                break;
            }
            else if(choose == 2)
            {
                cout << "请输入您想要搜索的账号：" << endl;
                string ID;
                cin >> ID;
                for(int k = 0; k < fol_num; k++)
                {
                    if(ID == fol[k].ID)
                    {
                        //cout << m_pro[k].ID << endl;
                        cout << "昵称：" << fol[k].username << endl;
                        cout << "真实姓名：" << fol[k].name << endl;
                        cout << "抖音号：" << fol[k].ID << endl;
                        cout << "邮箱：" << fol[k].mail_box << endl;
                        cout << "学校：" << fol[k].school << endl;
                        cout << "性别：" << fol[k].sex << endl;
                        cout << "生日：" << fol[k].birthday.year << "/"
                             << fol[k].birthday.month << "/"
                             << fol[k].birthday.day << endl;
                        cout << "地区：" << fol[k].area << endl;
                        cout << "总点赞数：" << fol[k].likes << endl;
                        
                        cout << "个人简介：" << fol[k].bio << endl;
                        cout << "\n\n";
                    }
                }
                break;
            }
            else
            {
                cout << "您的输入有误，请重新输入！" << endl;
            }
        }
    }
    else
    {
        cout << "文件是个空文件，没有数据！" << endl;
    }
}

//拉黑
void address::fol_setBlack()
{
    cout << "请通过以下两种方式确定用户" << endl;
    cout << "0.返回上一级菜单" << endl;
    cout << "1.按照列表查找" << endl;
    cout << "2.搜索" << endl;
    int choice;
    cin >> choice;
    
    while(1)
    {
        if(choice == 0)
        {
            return;
        }
        if(choice == 1)
        {
            fol_list();
        }
        else if(choice != 1 && choice != 2)
        {
            cout << "您的输入有误，请重新输入！" << endl;
            cout << "请通过以下两种方式确定用户" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.按照列表查找" << endl;
            cout << "2.搜索" << endl;
            cin >> choice;
            //用continue的特性，重新输入
            continue;
        }
        cout << "请输入该用户的用户名：" << endl;
        string name;
        cin >> name;
        //加入判断字符，判断是否存在该用户
        bool flag = false;
        for(int i = 0; i < fol_num; i++)
        {
            if(name == fol[i].username)
            {
                //更新数组长度
                int new_size;
                new_size = black_num + 1;
                //重新在堆区申请内存
                pro * new_black = new pro[new_size];
                //若有人在黑名单里
                if (black != NULL)
                {
                    //将原来的数据拷贝到新的数组里
                    for(int j = 0; j < black_num; j++)
                    {
                         new_black[j] = black[j];
                    }
                    //把想要拉黑的用户拉黑
                    new_black[new_size - 1] = fri[i];
                }
                //若无人在黑名单里
                else
                {
                    //把这个人设置为黑名单的第一个人
                    new_black[black_num] = fri[i];
                }
                //清空堆区数据
                delete []black;
                //更新数组
                black = new_black;
                black_num = new_size;
                //更新标志
                flag = true;
                //输出提示
                cout << "成功拉黑！" << endl;
                //保存到文件中
                black_save();
                //fri_save();
                m_FileIsEmpty_black = false;
            }
            
        }
        if(flag == false)
        {
            cout << "查无此人，请重新输入！" << endl;
            cout << "请通过以下两种方式确定用户" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.按照列表查找" << endl;
            cout << "2.搜索" << endl;
            cin >> choice;
            //用continue的特性，重新输入
            continue;
        }
        break;
    }
}

void address::fol_outFol()
{
    
    if(m_FileIsEmpty_fol == false)
        {
            cout << "请通过以下两种方式确定用户" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.按照列表查找" << endl;
            cout << "2.搜索" << endl;
            int choice;
            cin >> choice;
            while(1)
            {
                if(choice == 0)
                {
                    return;
                }
                if(choice == 1)
                {
                    //展示列表
                    fol_list();
                }
                else if(choice != 1 && choice != 2)
                {
                    cout << "您的输入有误，请重新输入！" << endl;
                    cout << "请通过以下两种方式确定用户" << endl;
                    cout << "0.返回上一级菜单" << endl;
                    cout << "1.按照列表查找" << endl;
                    cout << "2.搜索" << endl;
                    cin >> choice;
                    //用continue的特性，重新输入
                    continue;
                }
                cout << "请输入该用户的用户名：" << endl;
                string name;
                cin >> name;
                //加入判断字符，判断是否存在该用户
                bool flag = false;
                for(int i = 0; i < fol_num; i++)
                {
                    if(name == fol[i].username)
                    {
                        while(1)
                        {
                            cout << "您确定要将" << fol[i].username << "取消关注吗" << endl;
                            cout << "1.Yes " << endl;
                            cout << "2.No " << endl;
                            int choose;
                            cin >> choose;
                            if(choose == 1)
                            {
                                for(int j = i; j < fol_num - 1; j++)
                                {
                                    //数据前移
                                    fol[j] = fol[j + 1];
                                }
                                //更新数组中记录人员个数
                                fol_num--;
                                //更新标志
                                flag = true;
                                fol_save();
                                
                            }
                            else if(choose == 2)
                            {
                                break;
                            }
                            else
                            {
                                cout << "您的输入有误，请重新输入！" << endl;
                                
                                continue;
                            }
                            break;
                        }
                        break;
                    }
                }
                if(flag == false)
                {
                    cout << "查无此人，请重新输入！" << endl;
                    cout << "请通过以下两种方式确定用户" << endl;
                    cout << "0.返回上一级菜单" << endl;
                    cout << "1.按照列表查找" << endl;
                    cout << "2.搜索" << endl;
                    //用continue的特性，重新输入
                    continue;
                }
                break;
            }
        }
        else
        {
            cout << "文件是个空文件，没有数据！" << endl;
        }

}
//————————————————————————————————————————————————————————————//

//判断文件是否为空
void address::fan_judge()
{
    {
            //1.文件不存在
            ifstream ifs;
            ifs.open(FILE_FAN, ios::in);//读文件
            if (!ifs.is_open())//返回值是bool型
            {
                //cout << "文件不存在" << endl;
                //初始化记录人数
                fan_num = 0;
                //初始化数组指针
                fan = NULL;
                //初始化文件是否为空
                m_FileIsEmpty_fan = true;
                ifs.close();
                return;
            }
           //文件存在，但数据为空
            char ch;
            ifs >> ch;
            if(ifs.eof())
            {
                //cout << "文件为空" << endl;
                //初始化记录人数
                fan_num = 0;
                //初始化数组指针
                fan = NULL;
                //初始化文件是否为空
                m_FileIsEmpty_fan = true;
                ifs.close();
                return;
            }
            
            //文件存在，并且记录数据
        fan_num = fan_get_EmpNum();
            
            //开辟空间
        fan = new pro[fan_num];
            //将文件中的数据存到数组中
        fan_init();
            //更新职工不为空标志
            m_FileIsEmpty_fan = false;
    }
}
//统计文件中人数
int address::fan_get_EmpNum()
{
  
    ifstream ifs;
    ifs.open(FILE_FAN, ios::in);//打开文件 -- 读
    string username;//昵称
    string name;//真实姓名
    string ID;//抖音号
    string bio;//个人简介
    string mail_box;//邮箱
    string school;//学校
    string area;//地区
    int year;//生日
    int month;
    int day;
    char sex;//性别
    int likes;//总获赞数
    int num = 0;//记录数量
    while (ifs >> username && ifs >> name && ifs >> ID && ifs >> bio && ifs >> mail_box && ifs >> school && ifs >> year && ifs >> month && ifs >> day && ifs >> area && ifs >> sex && ifs >> likes)
    {
        num++;
    }
    ifs.close();
    return num;

}
//初始化
void address::fan_init()
{
    
    ifstream ifs;
    ifs.open(FILE_FAN, ios::in);

    string username;//昵称
    string name;//真实姓名
    string ID;//抖音号
    string bio;//个人简介
    string mail_box;//邮箱
    string school;//学校
    string area;//地区
    int year;//生日
    int month;
    int day;
    char sex;//性别
    int likes;//总获赞数
    int index = 0;
    while (ifs >> username && ifs >> name && ifs >> ID && ifs >> bio && ifs >> mail_box && ifs >> school && ifs >> year && ifs >> month && ifs >> day && ifs >> area && ifs >> sex && ifs >> likes)
    {
        fan[index].username = username;
        fan[index].name = name;
        fan[index].ID = ID;
        fan[index].bio = bio;
        fan[index].mail_box = mail_box;
        fan[index].school = school;
        fan[index].birthday.year = year;
        fan[index].birthday.month = month;
        fan[index].birthday.day = day;
        fan[index].area = area;
        fan[index].sex = sex;
        fan[index].likes = likes;
        index++;
    }
   
    ifs.close();

}
//保存文件
void address::fan_save()
{
    ofstream ofs;
    ofs.open(FILE_FAN, ios::out);//用输出的方式打开文件 -- 写文件
    for(int i = 0; i < fan_num; i++)
    {
        ofs << fan[i].username << " "
        << fan[i].name << " "
        << fan[i].ID << " "
        << fan[i].bio << " "
        << fan[i].mail_box << " "
        << fan[i].school << " "
        << fan[i].birthday.year << " "
        << fan[i].birthday.month << " "
        << fan[i].birthday.day << " "
        << fan[i].area << " "
        << fan[i].sex << " "
        << fan[i].likes << endl;
    }
    //关闭文件
    ofs.close();
}
//清空文件
void address::fan_Clean()
{
    
    if(m_FileIsEmpty_fan == true)
    {
        cout << "这是个空文件，无法删除！" << endl;
    }
    else
    {
        while(1)
        {
            cout << "确认清空？" << endl;
            cout << "1.确认" << endl;
            cout << "2.返回" << endl;
            int select = 0;
            cin >> select;
            if(select == 1)
            {
                //打开模式 ios::trunc 如果存在，则删除文件并重新创建
                ofstream ofs(FILE_FAN, ios::trunc);
                ofs.close();
                if (fan != NULL)
                {
                    delete []fan;
                    fan_num = 0;
                    fan = NULL;
                    m_FileIsEmpty_fan = true;
                }
                cout << "清除成功！" << endl;
                break;
            }
            else if(select == 2)
            {
                break;
            }
            else
            {
                cout << "您的输入有误，请重新输入！" << endl;
            }
        }
    }
   

}
//展示列表
void address::fan_list()
{
        
        if(m_FileIsEmpty_fan == false)
        {
            for(int i = 0; i < fan_num; i++)
                {
                    cout << "昵称：" << fan[i].username << endl;
                    cout << "真实姓名：" << fan[i].name << endl;
                    cout << "抖音号：" << fan[i].ID << endl;
                    cout << "邮箱：" << fan[i].mail_box << endl;
                    cout << "学校：" << fan[i].school << endl;
                    cout << "性别：" << fan[i].sex << endl;
                    cout << "生日：" << fan[i].birthday.year << "/"
                         << fan[i].birthday.month << "/"
                         << fan[i].birthday.day << endl;
                    cout << "地区：" << fan[i].area << endl;
                    cout << "总点赞数：" << fan[i].likes << endl;
                    
                    cout << "个人简介：" << fan[i].bio << endl;
                    cout << "\n\n";
                }
        }
        else
        {
            cout << "文件是一个空文件，没有数据！" << endl;
        }
        
}
//搜索功能
void address::fan_search()
{
    if(m_FileIsEmpty_fan == false)
    {
        while(1)
        {
            cout << "请输入您想要使用哪种搜索方式" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.昵称搜索" << endl;
            cout << "2.账号搜索" << endl;
            int choose;
            cin >> choose;
            if(choose == 0)
            {
                return;
            }
            if(choose == 1)
            {
                cout << "请输入您想要搜索的昵称：" << endl;
                string name;
                cin >> name;
                bool flag = false;
                for(int j = 0; j < fan_num; j++)
                {
                    if(name == fan[j].username)
                    {
                        //cout << m_pro[j].username << endl;
                        cout << "昵称：" << fan[j].username << endl;
                        cout << "真实姓名：" << fan[j].name << endl;
                        cout << "抖音号：" << fan[j].ID << endl;
                        cout << "邮箱：" << fan[j].mail_box << endl;
                        cout << "学校：" << fan[j].school << endl;
                        cout << "性别：" << fan[j].sex << endl;
                        cout << "生日：" << fan[j].birthday.year << "/"
                             << fan[j].birthday.month << "/"
                             << fan[j].birthday.day << endl;
                        cout << "地区：" << fan[j].area << endl;
                        cout << "总点赞数：" << fan[j].likes << endl;
                        
                        cout << "个人简介：" << fan[j].bio << endl;
                        cout << "\n\n";
                        flag = true;
                    }
                    
                }
                if(flag == false)
                {
                    cout << "查无此人！" << endl;
                }
                break;
            }
            else if(choose == 2)
            {
                cout << "请输入您想要搜索的账号：" << endl;
                string ID;
                cin >> ID;
                for(int k = 0; k < fan_num; k++)
                {
                    if(ID == fan[k].ID)
                    {
                        //cout << m_pro[k].ID << endl;
                        cout << "昵称：" << fan[k].username << endl;
                        cout << "真实姓名：" << fan[k].name << endl;
                        cout << "抖音号：" << fan[k].ID << endl;
                        cout << "邮箱：" << fan[k].mail_box << endl;
                        cout << "学校：" << fan[k].school << endl;
                        cout << "性别：" << fan[k].sex << endl;
                        cout << "生日：" << fan[k].birthday.year << "/"
                             << fan[k].birthday.month << "/"
                             << fan[k].birthday.day << endl;
                        cout << "地区：" << fan[k].area << endl;
                        cout << "总点赞数：" << fan[k].likes << endl;
                        
                        cout << "个人简介：" << fan[k].bio << endl;
                        cout << "\n\n";
                    }
                }
                break;
            }
            else
            {
                cout << "您的输入有误，请重新输入！" << endl;
            }
        }
    }
    else
    {
        cout << "文件是个空文件，没有数据！" << endl;
    }
}
//拉黑
void address::fan_setBlack()
{
    cout << "请通过以下两种方式确定用户" << endl;
    cout << "0.返回上一级菜单" << endl;
    cout << "1.按照列表查找" << endl;
    cout << "2.搜索" << endl;
    int choice;
    cin >> choice;
    
    while(1)
    {
        if(choice == 0)
        {
            return;
        }
        if(choice == 1)
        {
            fan_list();
        }
        else if(choice != 1 && choice != 2)
        {
            cout << "您的输入有误，请重新输入！" << endl;
            cout << "请通过以下两种方式确定用户" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.按照列表查找" << endl;
            cout << "2.搜索" << endl;
            cin >> choice;
            //用continue的特性，重新输入
            continue;
        }
        cout << "请输入该用户的用户名：" << endl;
        string name;
        cin >> name;
        //加入判断字符，判断是否存在该用户
        bool flag = false;
        for(int i = 0; i < fan_num; i++)
        {
            if(name == fan[i].username)
            {
                //更新数组长度
                int new_size;
                new_size = black_num + 1;
                //重新在堆区申请内存
                pro * new_black = new pro[new_size];
                //若有人在黑名单里
                if (black != NULL)
                {
                    //将原来的数据拷贝到新的数组里
                    for(int j = 0; j < black_num; j++)
                    {
                         new_black[j] = black[j];
                    }
                    //把想要拉黑的用户拉黑
                    new_black[new_size - 1] = fan[i];
                }
                //若无人在黑名单里
                else
                {
                    //把这个人设置为黑名单的第一个人
                    new_black[black_num] = fan[i];
                }
                //清空堆区数据
                delete []black;
                //更新数组
                black = new_black;
                black_num = new_size;
                //更新标志
                flag = true;
                //输出提示
                cout << "成功拉黑！" << endl;
                //保存到文件中
                black_save();
                //fri_save();
                m_FileIsEmpty_black = false;
            }
            
        }
        if(flag == false)
        {
            cout << "查无此人，请重新输入！" << endl;
            cout << "请通过以下两种方式确定用户" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.按照列表查找" << endl;
            cout << "2.搜索" << endl;
            cin >> choice;
            //用continue的特性，重新输入
            continue;
        }
        break;
    }
}
//关注
void address::fan_setFol()
{
    cout << "请通过以下两种方式确定用户" << endl;
    cout << "0.返回上一级菜单" << endl;
    cout << "1.按照列表查找" << endl;
    cout << "2.搜索" << endl;
    int choice;
    cin >> choice;
    
    while(1)
    {
        if(choice == 0)
        {
            return;
        }
        if(choice == 1)
        {
            fan_list();
        }
        else if(choice != 1 && choice != 2)
        {
            cout << "您的输入有误，请重新输入！" << endl;
            cout << "请通过以下两种方式确定用户" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.按照列表查找" << endl;
            cout << "2.搜索" << endl;
            cin >> choice;
            //用continue的特性，重新输入
            continue;
        }
        cout << "请输入该用户的用户名：" << endl;
        string name;
        cin >> name;
        //加入判断字符，判断是否存在该用户
        bool flag = false;
        for(int i = 0; i < fan_num; i++)
        {
            if(name == fan[i].username)
            {
                //更新数组长度
                int new_size;
                new_size = fol_num + 1;
                //重新在堆区申请内存
                pro * new_black = new pro[new_size];
                //若有人在关注里
                if (fol != NULL)
                {
                    //将原来的数据拷贝到新的数组里
                    for(int j = 0; j < fol_num; j++)
                    {
                         new_black[j] = fol[j];
                    }
                    //把想要关注的用户关注
                    new_black[new_size - 1] = fan[i];
                }
                //若无人在关注里
                else
                {
                    //把这个人设置为关注的第一个人
                    new_black[fol_num] = fan[i];
                }
                //清空堆区数据
                delete []fol;
                //更新数组
                fol = new_black;
                fol_num = new_size;
                //更新标志
                flag = true;
                //输出提示
                cout << "成功关注！！" << endl;
                //保存到文件中
                fol_save();
                //fri_save();
                m_FileIsEmpty_fol = false;
            }
            
        }
        if(flag == false)
        {
            cout << "查无此人，请重新输入！" << endl;
            cout << "请通过以下两种方式确定用户" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.按照列表查找" << endl;
            cout << "2.搜索" << endl;
            cin >> choice;
            //用continue的特性，重新输入
            continue;
        }
        break;
    }
}

//————————————————————————————————————————————————————————————//


//判断文件是否为空
void address::black_judge()
{
    {
            //1.文件不存在
            ifstream ifs;
            ifs.open(FILE_BLACK, ios::in);//读文件
            if (!ifs.is_open())//返回值是bool型
            {
                //cout << "文件不存在" << endl;
                //初始化记录人数
                black_num = 0;
                //初始化数组指针
                black = NULL;
                //初始化文件是否为空
                m_FileIsEmpty_black = true;
                ifs.close();
                return;
            }
           //文件存在，但数据为空
            char ch;
            ifs >> ch;
            if(ifs.eof())
            {
                //cout << "文件为空" << endl;
                //初始化记录人数
                black_num = 0;
                //初始化数组指针
                black = NULL;
                //初始化文件是否为空
                m_FileIsEmpty_black = true;
                ifs.close();
                return;
            }
            
            //文件存在，并且记录数据
        black_num = black_get_EmpNum();
            
            //开辟空间
        black = new pro[black_num];
            //将文件中的数据存到数组中
        black_init();
            //更新职工不为空标志
            m_FileIsEmpty_black = false;
    }
}
//统计文件中人数
int address::black_get_EmpNum()
{
    
    ifstream ifs;
    ifs.open(FILE_BLACK, ios::in);//打开文件 -- 读
    string username;//昵称
    string name;//真实姓名
    string ID;//抖音号
    string bio;//个人简介
    string mail_box;//邮箱
    string school;//学校
    string area;//地区
    int year;//生日
    int month;
    int day;
    char sex;//性别
    int likes;//总获赞数
    int num = 0;//记录数量
    while (ifs >> username && ifs >> name && ifs >> ID && ifs >> bio && ifs >> mail_box && ifs >> school && ifs >> year && ifs >> month && ifs >> day && ifs >> area && ifs >> sex && ifs >> likes)
    {
        num++;
    }
    ifs.close();
    return num;

}
//初始化
void address::black_init()
{
   
    ifstream ifs;
    ifs.open(FILE_BLACK, ios::in);

    string username;//昵称
    string name;//真实姓名
    string ID;//抖音号
    string bio;//个人简介
    string mail_box;//邮箱
    string school;//学校
    string area;//地区
    int year;//生日
    int month;
    int day;
    char sex;//性别
    int likes;//总获赞数
    int index = 0;
    while (ifs >> username && ifs >> name && ifs >> ID && ifs >> bio && ifs >> mail_box && ifs >> school && ifs >> year && ifs >> month && ifs >> day && ifs >> area && ifs >> sex && ifs >> likes)
    {
        black[index].username = username;
        black[index].name = name;
        black[index].ID = ID;
        black[index].bio = bio;
        black[index].mail_box = mail_box;
        black[index].school = school;
        black[index].birthday.year = year;
        black[index].birthday.month = month;
        black[index].birthday.day = day;
        black[index].area = area;
        black[index].sex = sex;
        black[index].likes = likes;
        index++;
    }
   
    ifs.close();

}

//清空文件
void address::black_Clean()
{
    
    if(m_FileIsEmpty_black == true)
    {
        cout << "这是个空文件，无法删除！" << endl;
    }
    else
    {
        while(1)
        {
            cout << "确认清空？" << endl;
            cout << "1.确认" << endl;
            cout << "2.返回" << endl;
            int select = 0;
            cin >> select;
            if(select == 1)
            {
                //打开模式 ios::trunc 如果存在，则删除文件并重新创建
                ofstream ofs(FILE_BLACK, ios::trunc);
                ofs.close();
                if (black != NULL)
                {
                    delete []black;
                    black_num = 0;
                    black = NULL;
                    m_FileIsEmpty_black = true;
                }
                cout << "清除成功！" << endl;
                break;
            }
            else if(select == 2)
            {
                break;
            }
            else
            {
                cout << "您的输入有误，请重新输入！" << endl;
            }
        }
    }
   

}
//保存文件
void address::black_save()
{
        ofstream ofs;
        ofs.open(FILE_BLACK, ios::out);//用输出的方式打开文件 -- 写文件
        for(int i = 0; i < black_num; i++)
        {
            ofs << black[i].username << " "
            << black[i].name << " "
            << black[i].ID << " "
            << black[i].bio << " "
            << black[i].mail_box << " "
            << black[i].school << " "
            << black[i].birthday.year << " "
            << black[i].birthday.month << " "
            << black[i].birthday.day << " "
            << black[i].area << " "
            << black[i].sex << " "
            << black[i].likes << endl;
        }
        //关闭文件
        ofs.close();
}
//添加喜欢作品
void address::Add_black()
{
  
    
    while (1)
    {
         cout << "请输入添加的用户数量：" << endl;
         int add_num = 0;
         cin >> add_num;
         bool flag = false;
         if(add_num > 0)
         {
             //计算新空间的大小
             int newSize = black_num + add_num;
             //开辟新空间
             pro * newSpace = new pro[newSize];
             //将原空间下内容拷贝到新空间下
             if(black != NULL)
             {
                 for(int i = 0; i < black_num; i++)
                 {
                     newSpace[i] = black[i];
                 }
             }
             //输入新数据
             for(int j = 0; j < add_num; j++)
             {
                 //创立一个临时的数组用于储存新增加的数据
                 pro short_time;
                 pro & shor = short_time;
                 cout << "请输入博主的昵称:";
                 cin >> short_time.username;
                 cout << "请输入博主的真实姓名：";
                 cin >> short_time.name;
                 cout << "请输入博主的抖音号:";
                 cin >> short_time.ID;
                 cout << "请输入博主的个人简介:" ;
                 cin >> short_time.bio;
                 cout << "请输入博主的邮箱:" ;
                 cin >> short_time.mail_box;
                 cout << "请输入博主的学校:" ;
                 cin >> short_time.school;
                 //添加地区
                 pro_management().set_area(shor);
                 //录入生日
                 pro_management().set_bir(shor);
                 //录入性别
                 pro_management().set_sex(shor);
                 cout << "请输入博主的总获赞数:" ;
                 cin >> short_time.likes;
                 newSpace[black_num + j] = short_time;
                 
             }
             //将原来的数据清空
             delete []black;
             black = newSpace;
             black_num = newSize;
             cout << "添加成功！" << endl;
             //保存数据到文件中
             black_save();
             //更改mFileEmpty
             m_FileIsEmpty_black = false;
         
          //提示添加成功
         cout << "成功将" << add_num << "个用户" << "加为好友！" << endl;
         }
         else
         {
             cout << "请重新输入" << endl;
         }
         if(flag == false)
         {
             break;
         }
     }

}
//展示列表
void address::black_list()
{
        
        if(m_FileIsEmpty_black == false)
        {
            for(int i = 0; i < black_num; i++)
                {
                    cout << "昵称：" << black[i].username << endl;
                    cout << "真实姓名：" << black[i].name << endl;
                    cout << "抖音号：" << black[i].ID << endl;
                    cout << "邮箱：" << black[i].mail_box << endl;
                    cout << "学校：" << black[i].school << endl;
                    cout << "性别：" << black[i].sex << endl;
                    cout << "生日：" << black[i].birthday.year << "/"
                         << black[i].birthday.month << "/"
                         << black[i].birthday.day << endl;
                    cout << "地区：" << black[i].area << endl;
                    cout << "总点赞数：" << black[i].likes << endl;
                    
                    cout << "个人简介：" << black[i].bio << endl;
                    cout << "\n\n";
                }
        }
        else
        {
            cout << "文件是一个空文件，没有数据！" << endl;
        }
        
}
//搜索功能
void address::black_search()
{
    if(m_FileIsEmpty_black == false)
    {
        while(1)
        {
            cout << "请输入您想要使用哪种搜索方式" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.昵称搜索" << endl;
            cout << "2.账号搜索" << endl;
            int choose;
            cin >> choose;
            if(choose == 0)
            {
                return;
            }
            if(choose == 1)
            {
                cout << "请输入您想要搜索的昵称：" << endl;
                string name;
                cin >> name;
                bool flag = false;
                for(int j = 0; j < black_num; j++)
                {
                    if(name == black[j].username)
                    {
                        //cout << m_pro[j].username << endl;
                        cout << "昵称：" << black[j].username << endl;
                        cout << "真实姓名：" << black[j].name << endl;
                        cout << "抖音号：" << black[j].ID << endl;
                        cout << "邮箱：" << black[j].mail_box << endl;
                        cout << "学校：" << black[j].school << endl;
                        cout << "性别：" << black[j].sex << endl;
                        cout << "生日：" << black[j].birthday.year << "/"
                             << black[j].birthday.month << "/"
                             << black[j].birthday.day << endl;
                        cout << "地区：" << black[j].area << endl;
                        cout << "总点赞数：" << black[j].likes << endl;
                        
                        cout << "个人简介：" << black[j].bio << endl;
                        cout << "\n\n";
                        flag = true;
                    }
                    
                }
                if(flag == false)
                {
                    cout << "查无此人！" << endl;
                }
                break;
            }
            else if(choose == 2)
            {
                cout << "请输入您想要搜索的账号：" << endl;
                string ID;
                cin >> ID;
                for(int k = 0; k < black_num; k++)
                {
                    if(ID == black[k].ID)
                    {
                        //cout << m_pro[k].ID << endl;
                        cout << "昵称：" << black[k].username << endl;
                        cout << "真实姓名：" << black[k].name << endl;
                        cout << "抖音号：" << black[k].ID << endl;
                        cout << "邮箱：" << black[k].mail_box << endl;
                        cout << "学校：" << black[k].school << endl;
                        cout << "性别：" << black[k].sex << endl;
                        cout << "生日：" << black[k].birthday.year << "/"
                             << black[k].birthday.month << "/"
                             << black[k].birthday.day << endl;
                        cout << "地区：" << black[k].area << endl;
                        cout << "总点赞数：" << black[k].likes << endl;
                        
                        cout << "个人简介：" << black[k].bio << endl;
                        cout << "\n\n";
                    }
                }
                break;
            }
            else
            {
                cout << "您的输入有误，请重新输入！" << endl;
            }
        }
    }
    else
    {
        cout << "文件是个空文件，没有数据！" << endl;
    }
}

void address::black_outBlack()
{
    if(m_FileIsEmpty_black == false)
        {
            cout << "请通过以下两种方式确定用户" << endl;
            cout << "0.返回上一级菜单" << endl;
            cout << "1.按照列表查找" << endl;
            cout << "2.搜索" << endl;
            int choice;
            cin >> choice;
            while(1)
            {
                if(choice == 0)
                {
                    return;
                }
                if(choice == 1)
                {
                    //展示列表
                    black_list();
                }
                else if(choice != 1 && choice != 2)
                {
                    cout << "您的输入有误，请重新输入！" << endl;
                    cout << "请通过以下两种方式确定用户" << endl;
                    cout << "0.返回上一级菜单" << endl;
                    cout << "1.按照列表查找" << endl;
                    cout << "2.搜索" << endl;
                    cin >> choice;
                    //用continue的特性，重新输入
                    continue;
                }
                cout << "请输入该用户的用户名：" << endl;
                string name;
                cin >> name;
                //加入判断字符，判断是否存在该用户
                bool flag = false;
                for(int i = 0; i < black_num; i++)
                {
                    if(name == black[i].username)
                    {
                        while(1)
                        {
                            cout << "您确定要将" <<   black[i].username << "拉出黑名单吗" << endl;
                            cout << "1.Yes " << endl;
                            cout << "2.No " << endl;
                            int choose;
                            cin >> choose;
                            if(choose == 1)
                            {
                                for(int j = i; j < black_num - 1; j++)
                                {
                                    //数据前移
                                    black[j] = black[j + 1];
                                }
                                //更新数组中记录人员个数
                                black_num--;
                                //更新标志
                                flag = true;
                                black_save();
                                
                            }
                            else if(choose == 2)
                            {
                                break;
                            }
                            else
                            {
                                cout << "您的输入有误，请重新输入！" << endl;
                                
                                continue;
                            }
                            break;
                        }
                        break;
                    }
                }
                if(flag == false)
                {
                    cout << "查无此人，请重新输入！" << endl;
                    cout << "请通过以下两种方式确定用户" << endl;
                    cout << "0.返回上一级菜单" << endl;
                    cout << "1.按照列表查找" << endl;
                    cout << "2.搜索" << endl;
                    //用continue的特性，重新输入
                    continue;
                }
                break;
            }
        }
        else
        {
            cout << "文件是个空文件，没有数据！" << endl;
        }
}

//————————————————————————————————————————————————————————————//

